package b1.mobile.blackberry.ui.component.util;

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.Manager;
import net.rim.device.api.ui.component.LabelField;
import net.rim.device.api.ui.container.HorizontalFieldManager;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.BackgroundFactory;

public class FieldFactory {

	static int COLOR_TITLE_TOP = 0x00333333;
	static int COLOR_TITLE_BOTTOM = 0x001F1F1F;
	
	public static Field makeScreenTitle(String title){
		Manager titleBarMgr = new HorizontalFieldManager(Field.USE_ALL_WIDTH);
		titleBarMgr.setPadding(10, 10, 10, 10);
		titleBarMgr.setBackground(BackgroundFactory.createLinearGradientBackground(COLOR_TITLE_TOP, COLOR_TITLE_TOP, COLOR_TITLE_BOTTOM, COLOR_TITLE_BOTTOM));
		
		Manager titleMgr = new VerticalFieldManager(Field.USE_ALL_WIDTH);
		
		LabelField label = new LabelField(title, Field.FIELD_HCENTER | LabelField.ELLIPSIS){
			protected void paint(Graphics graphics) {
				graphics.setColor(0x00f0ab00);
				super.paint(graphics);
			}
		};
		label.setFont(FontFactory.getFont(Font.BOLD, 7));
		titleMgr.add(label);
		
		titleBarMgr.add(titleMgr);
		return titleBarMgr;
	}
	
	public static Field makeGroupTitle(String title){
		LabelField label = new LabelField(title, LabelField.ELLIPSIS | Field.USE_ALL_WIDTH){
			protected void paint(Graphics graphics) {
				graphics.setColor(0x00ffffff);
				super.paint(graphics);
			}
		};
		
		label.setFont(FontFactory.getFont(Font.BOLD, 6));
		label.setBackground(BackgroundFactory.createLinearGradientBackground(0x00EFAA00, 0x00EFAA00, 0x00C38B00, 0x00C38B00));
		label.setPadding(5, 0, 5, 10);
		label.setMargin(10, 0, 0, 0);
		
		return label;
	}
}
